﻿using System.Collections.Generic;
using UnityEngine;
using VoxelBlock.VoxelBlock3D;
using VoxelBlock;using Vector3Int = VoxelBlock.Vector3Int;

public class OperationImplementBrushPaint : OperationImplement
{
    //public OperationImplementBrushPaint(ProxyOperation proxy) : base(proxy)
    //{

    //}

    public override void Start(StartArg arg)
    {
        base.Start(arg);

    }

    public override void Run(RunArg arg)
    {
        var arrayPoint = BasicAlgorithm.GetLineBlock3D(arg.updateStartPosition, arg.nowSelectPosition);
        //添加历史记录
        var data = nowDrawVoxel3DCore.DrawPaintBlock(arrayPoint, arg.nowSelectUVKey);
        historyRecordFrontList.AddRange(data.Item1);
        historyRecordBreakList.AddRange(data.Item2);
    }

    public override void Over(OverArg arg)
    {
        if (isStop)
        {
            if (historyRecordFrontList.Count > 0 || historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Paint, historyRecordFrontList, historyRecordBreakList);
                historyRecordBreakList = new List<SimpleVoxel>();
                historyRecordFrontList = new List<SimpleVoxel>();
            }
        }
        else
        {
            if (historyRecordFrontList.Count > 0 || historyRecordBreakList.Count > 0)
            {
                proxy.Write(VoxelCategories.Operation.Paint, historyRecordFrontList, historyRecordBreakList);
                historyRecordBreakList = new List<SimpleVoxel>();
                historyRecordFrontList = new List<SimpleVoxel>();
            }
            else
            {
                var data = nowDrawVoxel3DCore.DrawPaintBlock(new Vector3Int[] { arg.nowSelectPosition }, arg.nowSelectUVKey);
                if (data.Item1.Count > 0 || data.Item2.Count > 0)
                {
                    proxy.Write(VoxelCategories.Operation.Paint, data.Item1, data.Item2);
                }
            }
        }
    }
}


